/**
 * 
 * Copyright (C) 2015 by Elcom Software Company
 *
 * @id: FBPage.java, May 8, 2015
 *
 */
package com.nip.fblike.grapapi.page;

import org.json.JSONObject;

import com.nip.fblike.grapapi.GraphAPIBase;
import com.nip.fblike.grapapi.IFBLike;
import com.nip.fblike.graphobject.page.FBPageObject;

/**
 * @author ThangNM<thangnm@elcom.com.vn>
 *
 * @version v
 */
public class FBPage extends GraphAPIBase {

    /**
     * @param iFBLike
     */
    public FBPage(IFBLike iFBLike) {
        super(iFBLike);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.fblike.grapapi.IParserJson#parser(java.lang.String)
     */
    @Override
    public void parser(String json) {
        FBPageObject objec = new FBPageObject();
        try {
            if(json == null || json.trim().isEmpty())
            {
                objec.setEmpty(true);
                return;
            }
            JSONObject jsonObject = new JSONObject(json);
            objec.setId(jsonObject.getString("id"));
            objec.setLinks(jsonObject.getString("link"));
            objec.setName(jsonObject.getString("name"));
            objec.setLikes(jsonObject.getLong("likes"));

        } catch (Exception e) {
            objec.setEmpty(true);
        } finally {
            iFBLike.done(objec);
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.nip.fblike.grapapi.GraphAPIBase#getUrl()
     */
    @Override
    public String getUrl() {
        // TODO Auto-generated method stub
        return "https://graph.facebook.com/" + getUid() + "?access_token="
                + getAccess_token();
    }

}
